#include "mounter.h"
#include "provider_api.h"
#include "configuration.h"

MountedFilesystem* FsMount(const char *mount, FilesystemProvider *provider, const Configuration& cfg);

int Mounter::MountFilesystem(UserInterface *ui, const Configuration& cfg)
{
	std::string type = cfg.LookupSingle("type");
	FsCreateFunc func = FilesystemProvider::LookupFs(type);
	if(!func)
		return -1;
	std::string mount = cfg.LookupSingle("mount");
	if(mount.empty())
		return -2;

	FilesystemProvider *provider = func(ui, cfg);
	if(provider->Start()) {
		provider->Stop();
		delete provider;
		return -3;
	}
	MountedFilesystem *fs = FsMount(mount.c_str(), provider, cfg);
	MountInfo *info = new MountInfo();
	info->Mounted = fs;
	info->Mountpoint = mount;
	info->Provider = provider;
	return 0;
}

